home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 7.8 KB | 351 lines | [TEXT/MPS ] |
- /*
- File: Palette.cpp
-
- Contains: Palette Classes Implementation
-
- Written by: Dave Stafford
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- DrawEditor Includes --
-
- #ifndef _COMMAND_
- #include "Command.h"
- #endif
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- // -- OpenDoc Includes --
-
- // for ODName
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h" // ODDisposePtr
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- // -- Toolbox Includes --
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __MEMORY__
- #include <memory.h>
- #endif
-
-
- //-----------------------------------------------------------------------------
- // CCommand::CCommand
- //-----------------------------------------------------------------------------
-
- CCommand::CCommand(DrawEditor* theEditor,
- ODBoolean canUndo,
- ODBoolean changesContent,
- ODID undoTextIndex,
- ODID redoTextIndex)
- {
- fDrawEditor = theEditor;
- fCanUndo = canUndo;
-
- fChangesContent = changesContent;
- fActionType = kODSingleAction;
-
- fUndoTextIndex = undoTextIndex;
- fRedoTextIndex = redoTextIndex;
-
- fDoneState = 0;
-
- fUndo = kODNULL;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::~CCommand
- //-----------------------------------------------------------------------------
-
- CCommand::~CCommand()
- {
- fDrawEditor = NULL;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::SetActionType
- //-----------------------------------------------------------------------------
-
- void CCommand::SetActionType(ODActionType actionType)
- {
- fActionType = actionType;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::SetChangesContent
- //-----------------------------------------------------------------------------
-
- void CCommand::SetChangesContent(ODBoolean changesContent)
- {
- fChangesContent = changesContent;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::SetMenuTextIndexs
- //-----------------------------------------------------------------------------
-
- void CCommand::SetMenuTextIDs(ODID undoTextIndex, ODID redoTextIndex)
- {
- fUndoTextIndex = undoTextIndex;
- fRedoTextIndex = redoTextIndex;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::GetActionType
- //-----------------------------------------------------------------------------
-
- ODActionType CCommand::GetActionType() const
- {
- return fActionType;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::CanUndo
- //-----------------------------------------------------------------------------
-
- ODBoolean CCommand::CanUndo() const
- {
- return fCanUndo;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::ChangesContent
- //-----------------------------------------------------------------------------
-
- ODBoolean CCommand::ChangesContent() const
- {
- return fChangesContent;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::AbortCommand
- //-----------------------------------------------------------------------------
-
- void CCommand::AbortCommand(Environment* ev)
- {
- // Abort this transaction
- fUndo->AbortCurrentTransaction(ev);
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::WriteAction
- //-----------------------------------------------------------------------------
-
- void CCommand::WriteAction(Environment* ev, ODActionType actionType)
- {
- Str255 text;
- ODName* undoString = kODNULL;
- ODName* redoString = kODNULL;
-
- ODSLong tRef;
- tRef = BeginUsingLibraryResources();
-
- TRY
-
- // Get the undo string
- ::GetIndString(text, kMenuStringResID, fUndoTextIndex);
- undoString = CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text);
-
- // Get the redo string
- GetIndString(text, kMenuStringResID, fRedoTextIndex);
- redoString = CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text);
-
- // Make sure we don't pass NULL menu strings to OpenDoc!
- THROW_IF_NULL(undoString);
- THROW_IF_NULL(redoString);
-
- // Assume that the same command is used for begin & end actions
- void* temp = kODNULL;
- if (actionType!=kODEndAction)
- temp = &this;
- else
- temp = &(gGlobals->fZeroLong);
-
- ODActionData actionState;
-
- // Set up the action data
- actionState = ::CreateByteArrayStruct(temp, sizeof(temp));
-
- fUndo->AddActionToHistory(ev,
- fDrawEditor->GetODPart(), /* whichPart */
- &actionState, /* actionData */
- actionType, /* actionType */
- undoString, /* undoActionLabel */
- redoString); /* redoActionLabel */
-
- DisposeByteArrayStruct(actionState);
-
- CATCH_ALL
- ODSetSOMException(ev, ErrorCode());
-
- DebugStr("\pSetMenuItemText Failed.");
- ENDTRY;
-
- EndUsingLibraryResources(tRef);
-
- // Delete the IText data
- DisposeIText(undoString);
- DisposeIText(redoString);
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::DoCommand
- //-----------------------------------------------------------------------------
-
- void CCommand::DoCommand(Environment* ev)
- {
-
- // Capture the command state
- this->CaptureCommandState(ev);
-
- // for convenience, keep a reference to ODUndo
- if (this->CanUndo())
- {
- fUndo = fDrawEditor->GetSession(ev)->GetUndo(ev);
- }
-
- if (fChangesContent)
- fDrawEditor->SetDirty(ev);
-
- if (fCanUndo)
- {
- this->WriteAction(ev, fActionType);
- }
-
- fDoneState = kODDone;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::UndoCommand
- //-----------------------------------------------------------------------------
-
- void CCommand::UndoCommand(Environment* ev)
- {
- fDoneState = kODUndone;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::RedoCommand
- //-----------------------------------------------------------------------------
-
- void CCommand::RedoCommand(Environment* ev)
- {
- fDoneState = kODRedone;
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::Commit
- //
- // Here you want to clean up command specific structures depnding on the value of state.
- // For example, if a command creates a new piece of content and is comitted after being undone
- // then it should delete the structure representing the new content. Otherwise, it should not
- // deleted.
- //-----------------------------------------------------------------------------
-
- void CCommand::Commit(Environment* ev, ODDoneState state)
- {
- if (fChangesContent && (state == kODDone)||(state == kODRedone))
- {
- fDrawEditor->SetDirty(ev);
- }
- }
-
-
- //-----------------------------------------------------------------------------
- // CCommand::CaptureCommandState
- //
- // Here you want to save off any state info necessary for the command to be able to undo/redo.
- // Example: You might make a copy of a list of references to content that is being operated on
- // by the command.
- //-----------------------------------------------------------------------------
-
- void CCommand::CaptureCommandState(Environment* ev)
- {
-
- }
-
-
-
-
-
-